class Solution {
public:
    double findMaxAverage(vector<int>& nums, int k) {
        const int INF=0x3f3f3f3f;
        int n=nums.size();
        double ans=-INF,sum=0,av=0;
        for(int left=0,right=0;right<n;++right)
        {
            sum+=nums[right];
            while(left<right&&right-left+1>k)
            {
                sum-=nums[left++];
                
            }
            if(right-left+1==k) ans=max(ans,sum);
        }
        return ans/k;
    }
};